#!/bin/bash

# 身份证双面处理器 - 图形界面启动脚本 (Linux/macOS)

echo "=========================================="
echo "     身份证双面处理器 - 图形界面"
echo "=========================================="
echo

# 检查Python是否安装
if ! command -v python3 &> /dev/null; then
    echo "错误: 未找到Python3，请先安装Python 3.8或更高版本"
    exit 1
fi

# 检查Python版本
python_version=$(python3 -c 'import sys; print(".".join(map(str, sys.version_info[:2])))')
required_version="3.8"

if [ "$(printf '%s\n' "$required_version" "$python_version" | sort -V | head -n1)" != "$required_version" ]; then
    echo "错误: Python版本过低，需要Python 3.8或更高版本，当前版本: $python_version"
    exit 1
fi

# 检查虚拟环境
if [ -d "venv" ]; then
    echo "检测到虚拟环境，正在激活..."
    source venv/bin/activate
    echo "虚拟环境已激活"
    echo
fi

# 启动GUI应用
echo "正在启动身份证双面处理器..."
python3 gui/app.py

exit_code=$?

if [ $exit_code -ne 0 ]; then
    echo
    echo "启动失败，请检查Python环境和依赖包"
    echo "建议运行: pip3 install -r requirements.txt"
    echo
    read -p "按回车键继续..."
fi

exit $exit_code 